<template>
  <div class="GdwyyAppyxgdDetailTable">
    <GdwyyAppSmallTitle :title="pageTitle" :showDw="false"></GdwyyAppSmallTitle>

    <van-loading v-if="loading" type="spinner" color="#1989fa" />
    <a-table
      v-else
      :columns="pageConfig.tableColumns"
      :data-source="tableData"
      :bordered="true"
      :pagination="pageType == 'jfgd' ? false : pagination"
      size="small"
      :scroll="{ x: 1200, y: 500 }"
      @change="handleTableChange"
    >
    </a-table>
  </div>
</template>
  
  <script>
import moment from 'moment'
import { showZwtNav } from '@/utils/showNav.js'
import { postAction , sql2apiAction } from '@api/manage'
import { GdwyyAppSmallTitle } from '@/components/reconsitution/index.js'
import { detailApiConfig } from '../common'
export default {
  name: 'GdwyyAppyxgdDetailTable',
  components: { GdwyyAppSmallTitle },
  props: {
    showNav: {
      type: Boolean,
      default: true,
    },
    addQueryParam: {
      type: Object,
      default: () => {
        return {}
      },
    },
  },
  data() {
    return {
      pageTitle: '',
      queryParam: {},
      tableData: [],
      pagination: {
        position: 'bottom',
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0,
      },
      loading: false,
      pageType: '',
      
      url: {
        jfRymxch: '2c3a07178ba92724018bd2990ee50014',
        jfRymxXh: '2c3a07178ba92724018bd29b8b380015',
      },
    }
  },

  computed: {
    pageConfig() {
      return detailApiConfig[this.pageType]
    },
  },

  created() {
    const { pageTitle, queryParam, pageType } = this.$route.query
    this.$route.meta.title = this.pageTitle = pageTitle
    document.title = this.pageTitle
    this.pageType = pageType
    this.showNav && showZwtNav(pageTitle) // 根据情况判断是否显示(作为组件不显示)
    this.queryParam = JSON.parse(this.$route.query.queryParam)
    if ( this.pageType == 'jfgd' ) {
      this.getJfTableData()
    } else {
      this.getTableData()
    }
  },

  methods: {
    async getTableData() {
      this.loading = true
      const res = await postAction(`/Sql2ApiCall/call/${this.pageConfig.url}`, {
        ...this.queryParam,
        pageNum: Number(this.pagination.current),
        pageSize: Number(this.pagination.pageSize),
        ...this.addQueryParam
      })
      if (res.success) {
        let resultjson = JSON.parse(res.result)
        let resultdata = resultjson.data
        this.tableData = resultdata.list
        this.pagination.current = resultdata.pageNum || 1
        this.pagination.total = resultdata.total || 0
      } else {
        this.pagination.current = 0
        this.pagination.total = 0
      }
      this.loading = false
    },
    async getJfTableData() {
      // console.log(item)
      this.loading = true
      let url = ''
      if (this.queryParam.dayId == moment().format('YYYYMMDD')) url = this.url.jfRymxXh
      if (this.queryParam.dayId < moment().format('YYYYMMDD')) url = this.url.jfRymxch
      const res = await sql2apiAction(url, {
        ...this.queryParam,
        // pageNum: this.pagination.current,
        // pageSize: this.pagination.pageSize,
        ...this.addQueryParam
      })
      const data = res.result
      console.log('-----智家工程师列表', data)
      this.tableData = data
      this.loading = false
    },
    handleTableChange(pagination, filters, sorter) {
      this.pagination = pagination
      this.getTableData()
    },
  },
}
</script>
  
  <style lang="less" scoped>
.GdwyyAppyxgdDetailTable {
  padding: 0 8px;
  box-sizing: border-box;
  background: #fff;
  height: 100vh;
}
</style>